import { TOKEN_KEY } from './constant';

/**
 * 设置token
 * @param { string } token
 * @default ''
 */
export const setAccessToken = (token = '') => {
  window.sessionStorage.setItem(TOKEN_KEY, token);
};

/**
 * 获取token
 * @return { string } token
 */
export const getAccessToken = (): string => {
  return window.sessionStorage.getItem(TOKEN_KEY) || '';
};

/**
 * 删除token
 */
export const removeAccessToken = () => {
  window.sessionStorage.removeItem(TOKEN_KEY);
};

/**
 * 判断有无token
 * @return { boolean } true | false
 */
export const hasAccessToken = (): boolean => {
  return !!getAccessToken();
};
